package org.u2ml.stack.xml.xstream;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.u2ml.stack.xml.XmlStreamer;

public abstract class AbstractConverter {
	private final Logger logger = LoggerFactory.getLogger(AbstractConverter.class);

	@Autowired private XmlStreamer xmlStreamer;

	@PostConstruct
	public void init() {
		Component annotation = getClass().getAnnotation(Component.class);
		if (annotation != null) {
			xmlStreamer.registerLocalConverter(this, annotation.value());
		} else {
			throw new IllegalStateException(
					"converter classes MUST be annotated with @Component. " + getClass() + " doesn't!");
		}
	}
	
}
